﻿@inherits TextInputBase
@implements IHasJsonApiClient

@if (AppMetadata != null)
{
    <div class=@ClassNames("lookup-field", FieldClass)>
        <input type="hidden" name=@Input.Id value=@Value />
        @if (!string.IsNullOrEmpty(UseLabel))
        {
            <div class="flex justify-between">
                <label for=@Input.Id class=@ClassNames("block text-sm font-medium text-gray-700 dark:text-gray-300", LabelClass)>@UseLabel</label>
                @if (!string.IsNullOrEmpty(Value))
                {
                    <div class="flex items-center">
                        <span class="text-sm text-gray-500 dark:text-gray-400 mr-1">@Value</span>
                        <button @onclick="Clear" type="button" title="clear" class="mr-1 rounded-md text-gray-400 dark:text-gray-500 hover:text-gray-500 dark:hover:text-gray-400 focus:outline-none focus:ring-2 focus:ring-indigo-500 dark:ring-offset-black">
                            <span class="sr-only">Clear</span>
                            <svg class="h-4 w-4" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"></path></svg>
                        </button>
                    </div>
                }
            </div>
        }
        @if (Property.Ref != null)
        {
            <div class="mt-1 relative">
                <button type="button" class="lookup flex relative w-full bg-white dark:bg-black border border-gray-300 dark:border-gray-700 rounded-md shadow-sm pl-3 pr-10 py-2 text-left focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
                    @onclick="lookup" aria-haspopup="listbox" aria-expanded="true" aria-labelledby="listbox-label">
                    <span class="w-full inline-flex truncate">
                        <span class="text-blue-700 dark:text-blue-300 flex cursor-pointer">
                            <Icon class="mr-1 w-5 h-5" Image=@Icon />
                            <span>@refInfoValue</span>
                        </span>
                    </span>
                    <span class="absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none">
                        <svg class="h-5 w-5 text-gray-400 dark:text-gray-500" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
                            <path fill-rule="evenodd" d="M10 3a1 1 0 01.707.293l3 3a1 1 0 01-1.414 1.414L10 5.414 7.707 7.707a1 1 0 01-1.414-1.414l3-3A1 1 0 0110 3zm-3.707 9.293a1 1 0 011.414 0L10 14.586l2.293-2.293a1 1 0 011.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z" clip-rule="evenodd" />
                        </svg>
                    </span>
                </button>
            </div>
        }
        else if (ErrorFieldMessage != null)
        {
            <p class="mt-2 text-sm text-red-500" id=@($"{Input.Id}-error")>@ErrorFieldMessage</p>
        }
    </div>
    <DynamicModalLookup @ref="LocalModalLookup" AppMetadata=@AppMetadata />
}
